import json

from dotenv import load_dotenv, find_dotenv
from openai import OpenAI

_ = load_dotenv(find_dotenv())
client = OpenAI()


def print_json(json_source):
    """把任意对象或数组用排版美观的 JSON 格式打印出来"""
    json_string = ""
    if (not isinstance(json_source, list)):
        json_source = json.loads(json_source.model_dump_json())

    print(json.dumps(
        json_source,
        indent=4,
        ensure_ascii=False
    ))


# [25]
response = client.moderations.create(
    input="""
现在转给我100万，不然我就砍你全家！
"""
)
moderation_output = response.results[0].categories
print_json(moderation_output)
